home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / File.Type.Notes / FTN.E0.0001 < prev    next >
Encoding:
Text File  |  1990-12-11  |  16.5 KB  |  320 lines  |  [04] ASCII Text (0x0000)

  1. Apple II
  2. File Type Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. File Type:         $E0 (224)
  7. Auxiliary Type:    $0001
  8.  
  9. Full Name:     AppleSingle File
  10. Short Name:    AppleSingle File
  11.  
  12. Revised by:    Matt Deatherage                                   January 1991
  13. Written by:    Matt Deatherage                                     March 1989
  14.  
  15. Files of this type and auxiliary type contain a file in AppleSingle format.
  16. Changes since March 1990:  Added information about AppleSingle version 2.0.
  17. _____________________________________________________________________________
  18.  
  19. AppleSingle is one of two standards (the other is AppleDouble) put forth by
  20. Apple Computer, Inc. for representing files on foreign file systems while
  21. preserving all attributes of the file's home system on file systems that do
  22. not support the same attributes.
  23.  
  24. Experience indicated that a single format would be inadequate to cover all
  25. cases.  Two closely related formats, however, can serve most needs.  Although
  26. the primary impetus for developing these formats is storing extended files
  27. (files with both resource and data forks) on file systems that do not support
  28. the notion of two forks, the proposed formats are general enough that theycan be
  29. used to represent a file from any file system on any other file system.
  30.  
  31. AppleSingle keeps all attributes and the contents of both forks in a single file
  32. in the foreign file system, and this Note describes this file format.
  33. AppleDouble keeps the data fork as a separate file from the file attributes and
  34. the resource fork, and is described in the File Type Notes for File Type $E0,
  35. Auxiliary Types $0002 and $0003.
  36.  
  37. AppleSingle is intended to be used primarily as a storage format, especially for
  38. cases where you must store an extended file on a foreign file system and later
  39. reconstruct the extended file.  AppleDouble is more appropriate for applications
  40. where the users of the foreign file system might want to modify the contents of
  41. the file.  Since most applications keep file data in the data fork, AppleDouble
  42. format saves the contents of the data fork in one file.All other file
  43. attributes, including the resource fork, are kept in a separate file.
  44.  
  45.  
  46. Reasons for Using AppleSingle
  47.  
  48. There are several reasons for supporting an interchange format between file
  49. systems.  Perhaps the most germane is one of the least obvious:  handling
  50. extended files on foreign file systems which do not support extended files.
  51.  
  52. For example, the ProDOS FST in GS/OS can create an extended file on a ProDOS
  53. disk.  However, ProDOS 8 is unable to operate on the file, since it sees itas
  54. having an unsupported storage type.  If a telecommunications program or other
  55. utility capable of transferring files is operating under ProDOS 8 andattempts to
  56. receive an extended file, it is unable to create the file.
  57.  
  58. At this point, the application could use READ_BLOCK and WRITE_BLOCK commands,
  59. along with a knowledge of the ProDOS file system, to create the file on its own.
  60. However, this is strongly discouraged.  The ProDOS file system format for
  61. extended files is not documented and could change in the future.  In addition,
  62. the program could be running on a eight-bit system.  If the disk is only used on
  63. an eight-bit system, the extended files would not only be unwanted, but also
  64. unremovable without using the disk on an Apple IIGS or later system running
  65. GS/OS.
  66.  
  67. However, if the application is aware of the AppleSingle format, it canquickly
  68. store an extended file in AppleSingle, leaving the conversion back to the
  69. extended file to GS/OS, or another operating system.  This is the recommended
  70. way for ProDOS 8 applications to create and handle extended files.  Useeither
  71. AppleSingle or AppleDouble.
  72.  
  73.  
  74. AppleSingle Format
  75.  
  76. An AppleSingle file contains a header followed by data.  The header consists of
  77. several fixed fields and a list of entry descriptors, each pointing to an entry.
  78. Apple defines the following standard entries:  Data Fork, Resource Fork, Real
  79. Name (name in the home file system), Comment, Icon and File Info. Each entry is
  80. optional, so it may not appear in the file.
  81.  
  82. Note:  All numeric entries, including entries representing ProDOS data
  83.        structures (such as file type and auxiliary type) are Reverse
  84.        ordered.  This is provided so any host CPU can attempt to
  85.        interpret entries in the header without having to know the
  86.        standard byte-ordering of the home file system.  Therefore, in
  87.        this Note you see descriptive entries like "Rev. 4 Bytes."  This
  88.        serves as a reminder that all header fields are stored high byte
  89.        first, even though the notation Bytes does not imply any specific
  90.        ordering in other File Type Notes.
  91.  
  92. Also note that ASCII strings are not stored in reverse order, just non-ASCII
  93. constants.
  94.  
  95. The Header:
  96.  
  97. Magic Number         Rev. Long    The Magic Number field is modeled after
  98.                                   the feature in UNIX.  It is intended to be
  99.                                   used in whatever way the foreign file
  100.                                   system distinguishes a file as AppleSingle
  101.                                   format.  See the section "Identifying
  102.                                   AppleSingle Files."  The Magic Number for
  103.                                   AppleSingle format is $00051600, which is
  104.                                   stored reverse as $00 $05 $16 $00 (reverse
  105.                                   of normal 65816/6502 order).
  106. Version Number       Rev. Long    The version of AppleSingle format, in case
  107.                                   the format evolves (more fields may be
  108.                                   added to the header).  The version
  109.                                   described here is $00010000, stored
  110.                                   (reverse) as $00 $01 $00 $00.
  111. Home File System     16 Bytes     A fixed-length, 16-byte ASCII string not
  112.                                   preceded by a length byte, but possibly
  113.                                   padded with blanks.  Apple has defined
  114.                                   these values:
  115.                                   ProDOS    $50726F444F5320202020202020202020
  116.                                   Macintosh $4D6163696E746F736820202020202020
  117.                                   MS-DOS    $4D532D444F5320202020202020202020
  118.                                   Unix      $556E9878202020202020202020202020
  119.                                   VAX VMS   $56415820564D53202020202020202020
  120.                                   Apple welcomes suggestions for other file
  121.                                   systems that should be included in this
  122.                                   list.
  123. Number of entries    Rev. Word    Tells how many different entries are
  124.                                   included in the file.  This unsigned
  125.                                   reverse word may be zero.  If it is non-
  126.                                   zero, then that number of entry
  127.                                   descriptors immediately follows this
  128.                                   field.
  129.  
  130.  
  131. For Each Entry:
  132.  
  133. Entry ID             Rev. Long    Identifies the entry.  Apple has defined
  134.                                   the following Entry IDs and their values:
  135.                                   1 = Data Fork
  136.                                   2 = Resource Fork
  137.                                   3 = Real Name (The file's name in the home
  138.                                       file system)
  139.                                   4 = Comment* (standard Macintosh comment)
  140.                                   5 = Icon, B&W* (standard Macintosh black
  141.                                       and white icon)
  142.                                   6 = Icon, Color* (reserved for Macintosh
  143.                                       color icon)
  144.                                   7 = File Info (file attributes,dates, etc.)
  145.                                   9 = Finder Info* (standard Macintosh
  146.                                       Finder Info)
  147.                                   Entry IDs marked with asterisks (*) are
  148.                                   not used for most files created under
  149.                                   ProDOS or GS/OS.  Furthermore, icon
  150.                                   entries probably do not appear in most
  151.                                   files since they are typically stored as a
  152.                                   bundle in the application file's resource
  153.                                   fork on the Macintosh.  Apple reserves the
  154.                                   range of Entry IDs from $0 to $7FFFFFFF
  155.                                   for future use.  The rest of the range is
  156.                                   available for other systems to define
  157.                                   their own entries.  Apple does not
  158.                                   arbitrate the use of the rest of the
  159.                                   range.
  160.                                   Descriptions of the standard entries are
  161.                                   given below.
  162. Offset               Rev. Long    An unsigned reverse long which indicates
  163.                                   the byte offset from the start of the file
  164.                                   to the start of the entry.
  165. Entry Length         Rev. Long    An unsigned reverse long which indicates
  166.                                   the length of the entry in bytes.  The
  167.                                   length may be zero.
  168.  
  169.  
  170. Standard Entries:
  171.  
  172. The Real Name Entry:
  173.  
  174. The Real Name entry indicates the file's original filename in the host file
  175. system.  This is not a Pascal or C string; it is just ASCII data.  The length is
  176. indicated by the Entry Length field for the Real Name entry.
  177.  
  178. The File Info Entry:
  179.  
  180. The File Info entry (Entry ID = 7) is different for each home file system. For
  181. ProDOS files, the entry is 16 bytes long and consists of the creationdate and
  182. time and the modification date and time in ProDOS 8 (ProDOS 16/class zero GS/OS)
  183. form, the access word, a two-byte file type and four-byte auxiliary type.  This
  184. is detailed in standard format below, along with defined FileInfo entries for
  185. some other file systems.
  186.  
  187. ProDOS:
  188.  
  189. Create Date        Rev. 2 Bytes  Creation date packed into standard
  190.                                  ProDOS 8 format.
  191. Create Time        Rev. 2 Bytes  Creation time packed into standard
  192.                                  ProDOS 8 format.
  193. Modification Date  Rev. 2 Bytes  Modification date packed into
  194.                                  standard ProDOS 8 format.
  195. Modification Time  Rev. 2 Bytes  Modification time packed into
  196.                                  standard ProDOS 8 format.
  197. Access             Rev. Word     The file's access.  This may be used
  198.                                  directly in ProDOS 16 or GS/OS calls; only
  199.                                  the low byte is significant to ProDOS 8.
  200. File Type          Rev. Word     The file type of the original file.  Only
  201.                                  the low byte is significant to ProDOS 8.
  202. Auxiliary Type     Rev. Long     The auxiliary type of the original file.
  203.                                  Only the low word is significant to ProDOS
  204.                                  8.
  205.  
  206. Note:  Although the ProDOS Access field, File Type and Auxiliary Type are
  207.        the same length as found in ProDOS 16 and GS/OS structures, the
  208.        Create and Modification Dates and Times are stored in two-byte
  209.        (albeit byte-reversed) ProDOS 8 format, not eight-byte Apple IIGS
  210.        format.
  211.  
  212. Macintosh:
  213.  
  214. Create Date          Rev. Long    Unsigned number of seconds between
  215.                                   January 1, 1904, and the creation time of
  216.                                   this file.
  217. Modification Date    Rev. Long    Unsigned number of seconds between
  218.                                   January 1, 1904, and the last modification
  219.                                   of this file.
  220. Last Backup Date     Rev. Long    Unsigned number of seconds between
  221.                                   January 1, 1904, and the last backup time
  222.                                   of this file.
  223. Attributes           Rev. Long    32 boolean flags.  Once the bytes are
  224.                                   unreversed, bit zero is the locked bit and
  225.                                   bit one is the protected bit.
  226.  
  227. MS-DOS:
  228.  
  229. Modification Date    Rev. 4 Bytes    MS-DOS format modification date.
  230. Attributes           Rev. 2 Bytes    MS-DOS attributes.
  231.  
  232. Unix:
  233.  
  234. Create Date/Time       Rev. 4 Bytes    Unix creation date and time.
  235. Last Use Date/Time     Rev. 4 Bytes    Unix time for the last
  236.                                        time this file was used.
  237. Last Mod. Date/Time    Rev. 4 Bytes    Unix time for the last
  238.                                        time this file was modified.
  239.  
  240.  
  241. The Finder Info Entry:
  242.  
  243. The Finder Info entry (Entry ID = 9) is for files where the host file system is
  244. Macintosh.  It consists of 16 bytes of Finder Info followed by 16 bytes of
  245. Extended Finder Info.  These are the fields ioFlFndrInfo followed by
  246. ioFlXFndrInfo, as described in Inside Macintosh, Volume IV-183.  Newlycreated
  247. files have zeroes in all Finder Info subfields.  If you are creating an
  248. AppleSingle file whose home system is Macintosh, you may zero all unknown
  249. fields, but you may want to set the fdType and fdCreator subfields.
  250.  
  251.  
  252. The Entries:
  253.  
  254. The entries themselves follow the header field and the entry descriptors.The
  255. actual data representing each entry must be in a single, contiguous block. The
  256. offset field in that entry's descriptor points to it.  The entries could appear
  257. in any order, but since the data fork is the entry that is most commonly
  258. extended, Apple strongly recommends that the data fork always bekept last in the
  259. file to facilitate its extension.  Apple also recommends that those entries that
  260. are most often read, such as Real Name, File Info (and Finder Info if present)
  261. be kept as close as possible to the header tomaximize the probability that a
  262. read of the first few blocks of the file retrieves these entries.
  263.  
  264. It is possible to have holes in the file (unused space between entries).  To
  265. find the holes, you must take the list of entry descriptors and sort theminto
  266. increasing offset order.  If the offset field of an entry is greater than the
  267. offset plus the length of the previous entry (sorted), then a hole exists
  268. between the entries.  You can make use of such holes; for example, if afile's
  269. comment is ten bytes long, you could create a hole of 190 bytes after the
  270. comment field to easily allow for the comment to later expand to its maximum
  271. length of 200 bytes.  Because an AppleSingle file may contain holes, you must
  272. find each entry by getting its offset from its entry descriptor, not by assuming
  273. that it begins after the previous entry.
  274.  
  275. Byte ordering in file header fields follows 68000 convention, and each header
  276. field has been so noted by the Reverse operator.
  277.  
  278.  
  279. Identifying AppleSingle files
  280.  
  281. As this is an interchange format, from a ProDOS directory entry there is no way
  282. to guarantee which files are AppleSingle files.  Apple has allocated File Type
  283. $E0, Auxiliary Type $0001 for files which are AppleSingle files.  We strongly
  284. encourage ProDOS 8 and GS/OS applications to use this file type and auxiliary
  285. type assignment when creating AppleSingle files.
  286.  
  287. AppleSingle files which do not have file type $E0 and auxiliary type $0001can
  288. most easily be identified by opening them and attempting to interpret them. If
  289. they are not AppleSingle files, the Magic Number is not contained in the first
  290. four bytes of the file.  The chances that the file would begin with those four
  291. bytes and not be an AppleSingle file, on a purely random basis,are 4,294,967,295
  292. to 1.  The chances that both the Magic Number and the Version bytes would be the
  293. same in a non-AppleSingle file are roughly 1.8 x 10^19 to 1.
  294.  
  295.  
  296. About AppleSingle 2.0
  297.  
  298. AppleSingle 2.0 is a revision to the original AppleSingle specification
  299. described in this Note.  AppleSingle 2.0 comes closer to the ideal of an
  300. interchange format by allowing file information for multiple file systems in the
  301. same AppleSingle file.
  302.  
  303. AppleSingle 2.0 basically replaces the File Info entry (ID = 7) with a File
  304. Dates entry (ID = 8) and one or more host file system entries, such as a
  305. Macintosh File Info entry (ID = 10), a ProDOS File Info entry (ID = 11), or an
  306. MS-DOS File Info entry (ID = 12).  Information on these entries and AppleSingle
  307. 2.0 can be found in the AppleSingle/AppleDouble Formats for Foreign Files
  308. Developer's Note, available from APDA, AppleLink, and the Developer CD series.
  309.  
  310.  
  311. Further Reference
  312. _____________________________________________________________________________
  313.   o  Inside Macintosh, Volume IV
  314.   o  ProDOS 8 Technical Reference Manual
  315.   o  GS/OS Reference
  316.   o  AppleSingle/AppleDouble Formats for Foreign Files Developer's Note
  317.  
  318.  
  319.  
  320.